/* $Header: cx_cmds.c,v 2.2 01/10/02 10:29:14 przybyls Exp $ */

/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1991                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME: cx_cmds.c                                              */
/* ============                                                        */
/*                                                                     */
/* Author:  Bob Cook                                                   */
/*                                                                     */
/* MODULE PURPOSE: This module will handle the column commands.        */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

/*
 */

/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/

#include <typedefs.h>

#include <error.h>

#include <mio.h>
#include <cmd_set.h>
#include <cmdproc.h>
#include <method.h>
#include <hostutil.h>
#include <cmd_tbls.h>


/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/



/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/


/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/

extern CMD_QUEUE_TYPE  CX_Cmd_Q;

/*****************************/
/*   LOCAL DEFINES           */
/*****************************/


/*****************************/
/*   STATIC VARIABLES        */
/*****************************/


/*****************************/
/*   MACROS                  */
/*****************************/



/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/



/***********************************************************************/
/* FUNCTION: DoCXEO                                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Echo command.                                              */
/*                                                                     */
/* RETURNED VALUE: length of response string                           */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

INT16 DoCXEO(CMD_TYPE *p_cmd,BIT8  *p_resp_parm)
{
U_INT16 len;

   len = 0;

   if (p_cmd->parmv[0] == 1)
   {
      len = PutAsciiParam((BIT8 *)"\"", p_resp_parm);
      len += PutAsciiParam((BIT8 *)&(p_cmd->parms[p_cmd->parmv[1]]),
                                     p_resp_parm+len);
      len += PutAsciiParam((BIT8 *)"\"", p_resp_parm+len);
      return len;
   }
   else
   {
      CmdErrorHandler(p_cmd,1,INVALID_PARAM);
      return NO_RESPONSE;
   }
}

/***********************************************************************/
/* END FUNCTION: DoCXEO                                                */
/***********************************************************************/


INT16 FormatReturn ( BIT8 *p_resp_parm, U_INT8 parm_num, UI_ERR error )
{
   U_INT16 length = 0;

      length += PutIntParam  ( (INT32) error,     p_resp_parm+length,   0 );
      length += PutAsciiParam( (BIT8 *)",",       p_resp_parm+length      );
      length += PutIntParam  ( (INT32) parm_num,  p_resp_parm+length,   0 );

      return length;
}





/***********************************************************************/
/* FUNCTION: CXOpcodes                                                 */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: calls routines to implement the Cx commands.               */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* FILE SCOPE STATICS USED:                                            */
/*                                                                     */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

INT16 CXOpcodes(CMD_TYPE  *p_cmd,BIT8  *p_resp_parm,U_INT16 max_resp_len)
{
INT16           parm_len;

   (void) max_resp_len;

   parm_len = NO_RESPONSE;
   switch( p_cmd->opcode.int_op )
   {

      case MAKEINT( 'C', 'C' ):
        parm_len = (p_cmd->dsap.char_dsap[1] == '1') ?
                     DoCmdWithResponse(p_cmd,p_resp_parm,&mC1CC) :
                     DoCmdWithResponse(p_cmd,p_resp_parm,&mC2CC) ;
        break;

      case MAKEINT( 'I', 'C' ):
        parm_len = (p_cmd->dsap.char_dsap[1] == '1') ?
                     DoCmdWithResponse(p_cmd,p_resp_parm,&mC1IC) :
                     DoCmdWithResponse(p_cmd,p_resp_parm,&mC2IC) ;
        break;

      case MAKEINT( 'N', 'R' ):
        parm_len = (p_cmd->dsap.char_dsap[1] == '1') ?
                     DoCmd(p_cmd,p_resp_parm,&mC1NR) :
                     DoCmd(p_cmd,p_resp_parm,&mC2NR) ;
        break;

      case MAKEINT( 'P', 'W' ):
        parm_len = (p_cmd->dsap.char_dsap[1] == '1') ?
                     DoStatus(p_cmd,p_resp_parm,&mC1PW) :
                     DoStatus(p_cmd,p_resp_parm,&mC2PW) ;
        break;

      case MAKEINT( 'P', 'I' ):
        parm_len = (p_cmd->dsap.char_dsap[1] == '1') ?
                     DoCmd(p_cmd,p_resp_parm,&mC1PI) :
                     DoCmd(p_cmd,p_resp_parm,&mC2PI) ;
        break;

      case MAKEINT( 'F', 'I' ):
        parm_len = (p_cmd->dsap.char_dsap[1] == '1') ?
                     DoCmd(p_cmd,p_resp_parm,&mC1FI) :
                     DoCmd(p_cmd,p_resp_parm,&mC2FI) ;
        break;

      case MAKEINT( 'V', 'I' ):
        parm_len = (p_cmd->dsap.char_dsap[1] == '1') ?
                     DoCmd(p_cmd,p_resp_parm,&mC1VI) :
                     DoCmd(p_cmd,p_resp_parm,&mC2VI) ;
        break;

      case MAKEINT( 'C', 'F' ):
        parm_len = (p_cmd->dsap.char_dsap[1] == '1') ?
                     DoCmd(p_cmd,p_resp_parm,&mC1CF) :
                     DoCmd(p_cmd,p_resp_parm,&mC2CF) ;
        break;

      case MAKEINT( 'C', 'W' ):
        parm_len = (p_cmd->dsap.char_dsap[1] == '1') ?
                     DoCmd(p_cmd,p_resp_parm,&mC1CW) :
                     DoCmd(p_cmd,p_resp_parm,&mC2CW) ;
        break;

      case  MAKEINT('E','O'):
        parm_len = DoCXEO(p_cmd,p_resp_parm);
        break;

      default:
         parm_len = NO_RESPONSE;
         CmdErrorHandler(p_cmd,0,INVALID_OP);
         break;
   }

   return parm_len;
}


/***********************************************************************/
/* END FUNCTION: CXOpcodes                                             */
/***********************************************************************/




/***********************************************************************/
/* FUNCTION: CX_Cmds                                                   */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: calls function which executes a command if one is          */
/*          available on the command queue.                            */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/* FILE SCOPE STATICS USED:                                            */
/*                                                                     */
/*                                                                     */
/* CALLS:                                                              */
/*                                                                     */
/* LIMITATIONS:                                                        */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

void CX_Cmds(void)
{
   ExecCmds(&CX_Cmd_Q,CXOpcodes);
}

/***********************************************************************/
/* END FUNCTION: CX_Cmds                                               */
/***********************************************************************/

